package cn.antblog.ruankao.dynamicProgramming;

/**
 * @ClassName fib
 * @Description 动态规划  斐波那契数列
 * @Author YangJingyi
 * @Date 2023/9/22 17:00
 * @Version 1.0
 */
public class Fib {

    public static int fib(int n) {
        if (n <= 1) {
            return n;
        }
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for (int index = 2; index <= n; index++){
            dp[index] = dp[index - 1] + dp[index - 2];
        }
        return dp[n];
    }

    public static void main(String[] args) {
        fib(3);
        System.out.println(fib(3));
    }
}
